package br.uneb.tebd.local;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.uneb.tebd.R;
import br.uneb.tebd.model.Guitar;

public class LocalGuitarListAdapter extends BaseAdapter {
	
	private Context context;
	private List<Guitar> guitars;
	
	public LocalGuitarListAdapter(Context context, List<Guitar> guitars) {
		this.context = context;
		this.guitars = guitars;
	}
	
	public LocalGuitarListAdapter(Context context, Guitar guitar) {
		this.context = context;
		List<Guitar> guitars = new ArrayList<Guitar>();
		guitars.add(guitar);
		this.guitars = guitars;
	}

	public int getCount() {
		return this.guitars.size();
	}

	public Object getItem(int position) {
		return this.guitars.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Guitar guitar = this.guitars.get(position);
		
		LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View view = inflater.inflate(R.layout.list_item, null);
		
		TextView id = (TextView) view.findViewById(R.id.id);
		id.setText("Id: " + guitar.getId());
		
		TextView description = (TextView) view.findViewById(R.id.description);
		description.setText("Description: " + guitar.getDescription());
		
		TextView model = (TextView) view.findViewById(R.id.model);
		model.setText("Model: " + guitar.getModel());
		
		TextView brand = (TextView) view.findViewById(R.id.brand);
		brand.setText("Brand: " + guitar.getBrand());
		
		return view;
	}

}
